package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.basecom.billstatus.BillStatusConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.messagenotice.constructor.itf.IMessageNoticeConstructor;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;

public abstract class AbstractMessageNoticeConstructor<T extends Entity> implements IMessageNoticeConstructor<T> {

    public static final String APPROVAL_SUFFIX_ADOPT_MESSAGE = "已审批通过";

    public static final String APPROVAL_SUFFIX_REJECT_MESSAGE = "已被驳回";

    public static final String APPROVAL_SUFFIX_FAILED_MESSAGE = "需要重新提交审批";

    public static final String APPROVAL_PREFIX_MESSAGE = "您提交的";

    @Override
    public MessageNoticeVO[] generateNotice(T vo) throws BusinessException {
        return generateContent(vo);
    }

    protected abstract MessageNoticeVO[] generateContent(T vo) throws BusinessException;

    protected String getApprovalPrefixMessage(byte status) {
        if(BillStatusConst.COMMON_APPROVED_STATUS == status) {
            return APPROVAL_SUFFIX_ADOPT_MESSAGE;
        }else if(BillStatusConst.COMMON_REJECT_STATUS == status) {
            return APPROVAL_SUFFIX_REJECT_MESSAGE;
        }else if(BillStatusConst.COMMON_FREE_STATUS == status){
            return APPROVAL_SUFFIX_FAILED_MESSAGE;
        }
        return null;
    }

    public MessageNoticeVO coverBusinessVOToMessageVO(Entity vo){
        MessageNoticeVO noticeVO;
        if(vo == null){
            return null;
        }else if(vo instanceof MessageNoticeVO){
            noticeVO = (MessageNoticeVO)vo;
        }else {
            noticeVO = new MessageNoticeVO();
            noticeVO.setRelateKey(vo.pkFiledValue().toString());
        }
        return noticeVO;
    }

}
